package io.leo.leoui.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.List;

import io.leo.leoui.R;

public class ListDialog extends Dialog {

    private final Context mContext;
    private ListView mListView;

    public ListDialog(Context context, List<String> array) {
        super(context);
        mContext = context;
        initView();
        initListView(array);
    }

    private void initView() {
        View contentView = View.inflate(mContext, R.layout.content_list_dialog, null);
        mListView = contentView.findViewById(R.id.cld_list);
        setContentView(contentView);
    }

    public void setItemClickListener(AdapterView.OnItemClickListener listener){
        mListView.setOnItemClickListener(listener);
    }

    private void initListView(List<String> array) {

        ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(mContext, R.layout.item_array_list_single_line);
        stringArrayAdapter.addAll(array);
        mListView.setAdapter(stringArrayAdapter);
    }
}